package com.thinkgem.jeesite.modules.crawler.utils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class CommonUnitUtils {
	
	/**
	 * 对单位为"户",的数值进行处理，得到新的数值和单位
	 * @author mj 2017/2/24
	 * @param  value
	 * @param  unit
	 * @return map
	 */
	public static Map<String, Object> dealHouseholdUnit(Double value, String unit){
		if(value == null || StringUtils.isEmpty(unit)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		String hourseHoldUnit = "户";
		String qHourseHoldUnit = "千户";
		String wHourseHoldUnit = "万户";
		String qwhourseHoldUnit = "千万户";
		Double newValue = 0.0;
		String newUnit = "";
		newValue = value;
		newUnit = hourseHoldUnit;
		map.put("value", newValue);
		map.put("unit", newUnit);
		return map;
	}
	
	/**
	 * 对单位为"个",的数值进行处理，得到新的数值和单位
	 * @author mj 2017/2/24
	 * @param  value
	 * @param  unit
	 * @return map
	 */
	public static Map<String, Object> dealAUnit(Double value, String unit){
		if(value == null || StringUtils.isEmpty(unit)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		String aUnit = "个";
		String qAUnit = "千个";
		String wAUnit = "万个";
		String qwAUnit = "千万个";
		Double newValue = 0.0;
		String newUnit = "";
		newValue = value;
		newUnit = aUnit;
		map.put("value", newValue);
		map.put("unit", newUnit);
		return map;
	}
	
	/**
	 * 对单位为"万元",的数值进行处理，得到新的数值和单位
	 * @author mj 2017/2/24
	 * @param  value
	 * @param  unit
	 * @return map
	 */
	public static Map<String, Object> dealTenThousandYuanUnit(Double value, String unit){
		if(value == null || StringUtils.isEmpty(unit)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		String tenThousandYuanUnit = "万元";
		String tenMillionYuanUnit = "千万元";
		String hundredMillionUnit = "亿元";
		Double newValue = 0.0;
		String newUnit = "";
		newValue = value;
		newUnit = tenThousandYuanUnit;
		map.put("value", newValue);
		map.put("unit", newUnit);
		return map;
	}
	
	/**
	 * 对单位为"万美元",的数值进行处理，得到新的数值和单位
	 * @author mj 2017/2/24
	 * @param  value
	 * @param  unit
	 * @return map
	 */
	public static Map<String, Object> dealTenThousandDollarUnit(Double value, String unit){
		if(value == null || StringUtils.isEmpty(unit)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		String tenThousandDollarUnit = "万美元";
		String tenMillionDollarUnit = "千万美元";
		String hundredMillionUnit = "亿美元";
		Double newValue = 0.0;
		String newUnit = "";
		newValue = value;
		newUnit = tenThousandDollarUnit;
		map.put("value", newValue);
		map.put("unit", newUnit);
		return map;
	}

	/**
	 * 如果单位是"万元"，数值过长，到达"亿"的级别，把单位换成"亿"
	 * @author mj 2017/4/26
	 * @param  value
	 * @param  unit
	 * @return map
	 */
	public static Map<String, Object> dealBigDecimalUnit(BigDecimal value, String unit) {
		if(value == null || StringUtils.isBlank(unit)){
			return null;
		}
		Map<String, Object> map = new HashMap<String, Object>();
		String newUnit = "";
		BigDecimal compareValue = new BigDecimal("10000");
		if(value.compareTo(compareValue) >= 0) {
			value = value.divide(compareValue);
			newUnit = "亿元";		
		} else {
			newUnit = "万元";
		}
		map.put("value", value);
		map.put("unit", newUnit);
		return map;
	}
}
